package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SjStandardProblem;
import com.ruoyi.system.service.ISjStandardProblemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标准问题Controller
 * 
 * @author ruoyi
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/system/problem")
public class SjStandardProblemController extends BaseController
{
    @Autowired
    private ISjStandardProblemService sjStandardProblemService;

    /**
     * 查询标准问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:list')")
    @GetMapping("/list")
    public TableDataInfo list(SjStandardProblem sjStandardProblem)
    {
        startPage();
        List<SjStandardProblem> list = sjStandardProblemService.selectSjStandardProblemList(sjStandardProblem);
        return getDataTable(list);
    }

    /**
     * 导出标准问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:export')")
    @Log(title = "标准问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SjStandardProblem sjStandardProblem)
    {
        List<SjStandardProblem> list = sjStandardProblemService.selectSjStandardProblemList(sjStandardProblem);
        ExcelUtil<SjStandardProblem> util = new ExcelUtil<SjStandardProblem>(SjStandardProblem.class);
        util.exportExcel(response, list, "标准问题数据");
    }

    /**
     * 获取标准问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:problem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sjStandardProblemService.selectSjStandardProblemById(id));
    }

    /**
     * 新增标准问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:add')")
    @Log(title = "标准问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SjStandardProblem sjStandardProblem)
    {
        return toAjax(sjStandardProblemService.insertSjStandardProblem(sjStandardProblem));
    }

    /**
     * 修改标准问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:edit')")
    @Log(title = "标准问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SjStandardProblem sjStandardProblem)
    {
        return toAjax(sjStandardProblemService.updateSjStandardProblem(sjStandardProblem));
    }

    /**
     * 删除标准问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:remove')")
    @Log(title = "标准问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sjStandardProblemService.deleteSjStandardProblemByIds(ids));
    }
}
